const jwt =require('jsonwebtoken')
const authenticationList =[  '/api/info']
module.exports =()=>{
    return async function authentication(ctx,next){
        const token=ctx.cookies.get('token')
        if(authentication.indexOf(ctx.request.path) !==-1){
            const user =jwt.verify(token,'***')
            if(user){
                ctx.userInfo=user
                await next()
            }else{
                if(token){
                    ctx.throw(401,'用户登陆失败')
                }else{
                    ctx.throw(401,'用户未登陆')
                }
            }
        }  else{
            await next()
        }
    }
}  
